<?php include("/includes/header.php") ?>
<?php include("/includes/sidebar.php") ?>

<div class="content row-fluid"> 
	<div class="span12 table-placer">
		<div class="alert alert-info"><h4>Room Listing</h4></div>
		<div class="row-fluid index-pos-placer">
			<?php  
				$roomStatus = "";
				// $dataRoom = fetchData("room");
				$sql = "SELECT * FROM (SELECT * FROM  occupied
										UNION 
										SELECT *, '0' AS 'status' FROM room WHERE id NOT IN (SELECT id FROM occupied) AND is_active = 1
						) AS fo
						ORDER BY fo.id ASC";
				// echo $sql;
				$query = mysql_query($sql);
				$i = 1;
				while ($data = mysql_fetch_array($query)) {
					$roomStatus = "";
					if ($data["status"] == 1) {
						$sqlRoomDweller = "SELECT * FROM front_office WHERE idroom = '".$data["id"]."' AND is_paid = 0";
						// echo $sqlRoomDweller;
						$queryRoomDweller = mysql_query($sqlRoomDweller);
						$dataRoomDweller = mysql_fetch_array($queryRoomDweller);
						$roomStatus = "booked";
						$roomHTML = "<p class='text-warning'>Room is occupied <i class='fa fa-lock'></i></p>";
						$roomHTML .= "<dl>
										<dt>Name</dt>
										<dd>".$dataRoomDweller["nama"]."</dd>
										<dt>Since</dt>
										<dd>".date(  "F j, Y", strtotime( $dataRoomDweller["checkin"] ) )." at ".date(  "H:i", strtotime( $dataRoomDweller["checkin"] ) )."</dd>
									</dl>
									<div class='row-fluid'>
									<a href='fo-checkout.php?".trim(base64_encode("id"), '=')."=".base64_encode($dataRoomDweller["id"])."' class='btn btn-info'>Checkout</a>
									<a href='fo-room-info.php?".trim(base64_encode("idroom"), '=')."=".base64_encode($data["id"])."' class='btn btn-info'>Room Activity</a>
									<a href='fo_room_services.php?".trim(base64_encode("id"), '=')."=".base64_encode($dataRoomDweller["id"])."' class='btn btn-info'>Room Service</a>
									</div>
									";
					} else {
						$roomHTML = "<p class='text-success'>Room is available to book <i class='fa fa-unlock'></i></p>
									<div class='row-fluid'>
									<a href='fo-checkin.php?".trim(base64_encode("idroom"), '=')."=".base64_encode($data["id"])."' class='btn'>Checkin</a>
									<a href='fo-room-info.php?".trim(base64_encode("idroom"), '=')."=".base64_encode($data["id"])."' class='btn btn-info'>Room Activity</a>
									</div>
									";
					}
					if (($i-1)%4 == 0) {
			?>
		</div>
		<div class="row-fluid index-pos-placer">
			<?php
					}
			?>
				<span class="span3 index-pos <?php echo $roomStatus; ?>" data-toggle="popover" title="" data-html="true" data-content="<?php echo $roomHTML; ?>" data-original-title="Room Status" data-placement="top">
					<a href="#">
						<div>
							<?php echo $data["nama"]; ?>
						</div>
					</a>
				</span>
			<?php
					$i++;
				}
			?>
		</div>
	</div>           
</div>

<div class="footer">
</div>

<?php include("/includes/footer.php") ?>   

<script type="text/javascript">
	$(document).ready(function() {
		var elPop;
		$('.index-pos').popover({
			animation: false
		});
		$('.table-placer').on('click', '.index-pos', function(event) {
			event.preventDefault();
			/* Act on the event */
			// elPop = $(this);
			// $(this).popover("show");
			if (!$(this).next().hasClass('in')) {
				$(".index-pos").popover("hide");
				$(this).popover("hide");
			} else {
				$(".index-pos").popover("hide");
				$(this).popover("show");
			}
		});
	});
</script>        